package com.paso.westpark.controller;

import com.paso.westpark.pojo.Record;
import com.paso.westpark.service.IRecordService;
import com.paso.mycommons.vo.RespBean;
import com.paso.mycommons.vo.RespBeanEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wangx
 * @since 2021-02-14
 */
@RestController
@RequestMapping("/record")
@Slf4j
public class RecordController {


    @Resource
    IRecordService recordService;


    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }


//
//    @RequestMapping(value = "selectByCarNo", method = RequestMethod.POST)
//    public RespBean selectByCarNo(@RequestParam(value = "CarNO", required = false) String CarNO,
//                                  @RequestParam(value = "icno", required = false)String icno) {
//        try {
//            log.info(CarNO);
//            log.info(icno);
//            if (null == CarNO || StringUtils.isEmpty(CarNO)){
//                CarNO = "22222222222222";
//
//            }
//            if (null == icno || StringUtils.isEmpty(icno) ){
//                icno = "222222222222222222";
//            }
//            List<Record> records = recordService.selectByCarNo(CarNO, icno);
//            System.out.println("------------------------");
//            for (Record record : records) {
//                log.info(String.valueOf(record));
//            }
//            return RespBean.success(records);
//        } catch (Exception e) {
//            return RespBean.error(RespBeanEnum.QUERY_FAIL);
//        }
//
//    }


    @RequestMapping(value = "deleteById", method = RequestMethod.GET)
    public RespBean deleteById(Record record) {
        try {
            Integer id = record.getId();
            recordService.deleteById(id);
        } catch (Exception e) {
            return RespBean.error(RespBeanEnum.DELETE_FAIL);
        }
        return RespBean.success();
    }

    @RequestMapping(value = "selectByCarNo", method = RequestMethod.POST)
    public RespBean selectByCarNo1(@RequestParam(value = "CarNO", required = false) String CarNO) {

        if (null == CarNO || StringUtils.isEmpty(CarNO)) {
            CarNO = "22222222222222";
        }

        List<Record> records = recordService.selectByCarNo(CarNO);
        for (Record record : records) {
            log.info(String.valueOf(record));
        }
        return RespBean.success(records);
    }


    @RequestMapping(value = "selectByIcno", method = RequestMethod.POST)
    public RespBean selectByIcno(@RequestParam(value = "icno", required = false) String icno) {

        if (null == icno || StringUtils.isEmpty(icno)) {
            icno = "22222222222222";
        }

        log.info("icno====" + icno);
        List<Record> records = recordService.selectByIcno(icno);

        return RespBean.success(records);
    }

}
